/**
 * @name        sfxObject
 * @author      shenyc
 * @date        2021-08-10
 * @copyright   Copy right (c) shenyc (shenyczz@163.com).
 *              All rights reserved.
 *
 ******************************************************************************/
// {{@@@}}
"use strict";
// ----------------------------------------------------------------------------
import * as ol from "ol";
import * as layer from "ol/layer";
import * as source from "ol/source";
import * as control from "ol/control";
import * as coordinate from "ol/coordinate";
import * as proj from "ol/proj";
import * as extent from "ol/extent";

import { Map, View } from "ol";
import BaseLayer from "ol/layer/Base";

import sfxObject from "./sfxObject";

export class sfxOpenLayers extends sfxObject {
    constructor(parameters?: any) {
        super(parameters);

        this._map = new ol.Map({
            target: "",
            layers: [],
            view: undefined,
            controls: control.defaults({ attribution: false }).extend([
                // new control.Attribution(),  // 用于展示地图资源的版权或者归属，它会默认加入到地图中。
                // new control.Control(""),
                // new control.FullScreen(),    // 控制地图全屏展示
                // new control.MousePosition(), // 用于在地图上拾取坐标
                // new control.OverviewMap(),   // 生成地图的一个概览图
                // new control.Rotate(),           // 用于鼠标拖拽旋转地图，它会默认加入到地图中。
                // new control.ScaleLine(),        // 用于生成地图比例尺
                // new control.Zoom(),             // 普通缩放控件，它会默认加入到地图中。
                // new control.ZoomSlider(),             // 以滑块的形式缩放地图
                // 用于将地图视图缩放至特定位置 `[minx, miny, maxx, maxy]
                new control.ZoomToExtent({ label: "H", tipLabel: "将地图视图缩放至特定位置" }),
            ]),
        });

        this._view = this._map.getView();
    }

    private _map: Map;
    private _view: View;
    private _mousePosition?: control.MousePosition;

    public get Map() {
        return this._map;
    }
    public get View() {
        return this._view;
    }

    /**
     * 初始化
     */
    public override init(): void {
        const view = new ol.View({
            center: [0, 0],
            zoom: 2,
        });

        const osmLayer = new layer.Tile({
            // name: 'osm layer',
            source: new source.OSM({}),
            visible: true,
        });

        const debugLayer = new layer.Tile({
            // name: 'debug layer',
            source: new source.TileDebug(),
            visible: true,
        });

        this._map.setView(view);
        // map.addLayer(osmLayer);
        this._map.addLayer(debugLayer);
    }

    // olMap
    public static ok: boolean = false;

    public static instance = new sfxOpenLayers();

    // {{END}}
}

export default sfxOpenLayers.instance;
// ----------------------------------------------------------------------------
// {{@@@}}
